package com.qf.contorller;

import com.qf.pojo.User;
import com.qf.service.UserService;
import com.qf.utils.R;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @author zdl
 * @date 2025/2/15
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @PostMapping("/login")
    public R<User> loginUser(@RequestBody User user, HttpSession session) {
        User user1 = userService.loginUser(user, session);
        return R.ok(user1);
    }

    @PostMapping("/logout")
    public R<?> logout(HttpSession session) {
        session.removeAttribute("session");
        return R.ok("退出成功");
    }

}
